package com.ml.mall.api.sys;

import com.ml.mall.annotation.LogMethodInvokeInformation;
import com.ml.mall.annotations.OperLog;
import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.sys.SysRoleEditDto;
import com.ml.mall.bean.req.sys.SysRoleNewDto;
import com.ml.mall.bean.req.sys.SysRoleQueryDto;
import com.ml.mall.enums.RetStatusNum;
import com.ml.mall.service.sys.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* <p>
    * 用户角色表 前端控制器
    * </p>
*
* @author kyyang
* Created 2021-01-20
*/

@Api(tags = "【auth】角色")
@RestController
@RequestMapping("/role")
public class SysRoleController extends BaseController {

     @Autowired
     private ISysRoleService sysRoleService;


    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("角色查询")
//  @RequiresPermissions(PermissionConst.ROLE_QUERY)
    @LogMethodInvokeInformation
    public ApiRestResult sysRoleQuery(@RequestBody SysRoleQueryDto sysRoleQueryDto) {
        return ApiRestResult.ok(sysRoleService.sysRoleByPage(sysRoleQueryDto));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "角色新建", operModul = "role", operType = "new")
    @ApiOperation("角色新建")
//  @RequiresPermissions(PermissionConst.ROLE_NEW)
//    @LogMethodInvokeInformation
    public ApiRestResult sysRoleNew(@Valid @RequestBody SysRoleNewDto sysRoleNewDto ) {
        return ApiRestResult.ok(sysRoleService.sysRoleNew(sysRoleNewDto));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @OperLog(operDesc = "角色修改", operModul = "role", operType = "edit")
    @ApiOperation("角色修改")
//  @RequiresPermissions(PermissionConst.ROLE_EDIT)
    public ApiRestResult sysRoleEdit(@Valid @RequestBody SysRoleEditDto sysRoleEditDto ) {
        return ApiRestResult.ok(sysRoleService.sysRoleEdit(sysRoleEditDto));
    }


    @PostMapping("/del")
    @OperLog(operDesc = "角色删除", operModul = "role", operType = "del")
    @ApiOperation("角色删除")
//  @RequiresPermissions(PermissionConst.ROLE_DEL)
    public ApiRestResult sysRoleDel(@RequestBody List<Integer> ids) {
        if(ids==null||ids.size()<1){
            return ApiRestResult.err(RetStatusNum.PARAMS_ERROR.getMessage(), RetStatusNum.PARAMS_ERROR.getCode());
        }
        return ApiRestResult.ok(sysRoleService.sysRoleDel(ids));
    }
}
